package cn.com.w.spring.thread.pool.controller;

import cn.com.w.common.thread.bean.ListTestData;
import cn.com.w.common.thread.worker.SendDataWorker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.DependsOn;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.List;

@Component
@DependsOn(value = {"springFrameworkExector"})
public class SendDataController {

    Logger log = LoggerFactory.getLogger(SendDataController.class);


    @Resource(name = "springFrameworkExector")
    TaskExecutor taskExecutor;


    public void sendData() {

        List<String> stringList = ListTestData.getTestData();

        Iterator<String> iterator = stringList.iterator();
        while (iterator.hasNext()) {
            String str = iterator.next();
            // spring框架线程池
            taskExecutor.execute(new SendDataWorker(str));
            int maximumPoolSize =  Runtime.getRuntime().availableProcessors();
            log.info("服务器可使用进程数量：[{}]", maximumPoolSize);

        }
    }

}